#include "TextureCube.h"
#include "Object/NewObject.h"
#include "Render/Texture/RenderTextureCube.h"

TSharedObjectPtr<RTextureCube> RTextureCube::CreateFromCreateInfo(STextureCubeCreateInfo &&InCreateInfo, RObject *InOwner)
{
    auto TextureCube = NewObject<RTextureCube>(InOwner);
    TextureCube->Width = InCreateInfo.Width;
    TextureCube->Height = InCreateInfo.Height;
    TextureCube->Pitch = InCreateInfo.Pitch;
    TextureCube->Format = InCreateInfo.Format;
    TextureCube->Front = InCreateInfo.Front;
    TextureCube->Back = InCreateInfo.Back;
    TextureCube->Left = InCreateInfo.Left;
    TextureCube->Right = InCreateInfo.Right;
    TextureCube->Top = InCreateInfo.Top;
    TextureCube->Bottom = InCreateInfo.Bottom;
    TextureCube->bDirty = true;
    TextureCube->SyncToRenderThread();

    return TextureCube;
}

RTextureCube::RTextureCube()
{
    RenderTexture =  std::make_shared<CRenderTextureCube>();
}

void RTextureCube::SyncToRenderThread()
{
    if(bDirty)
    {
        bDirty=false;
        
        ForceSyncToRenderThread();
    }
}

std::shared_ptr<CRenderTextureCube> RTextureCube::GetRenderTexture()
{
    return RenderTexture;
}

void RTextureCube::ForceSyncToRenderThread()
{
    bDirty=false;

    RenderTexture->SyncToRenderThread(Width,Height,Pitch,Format,Front,Back,Left,Right,Top,Bottom);
}